"""
失败记录请求模型
"""
from dataclasses import dataclass
from typing import Optional, Dict, Any
from datetime import datetime


# 注意：dataclass 继承时，子类不能有无默认值参数如果父类有默认值参数
# 所以这里不使用继承，而是在每个类中重复定义基础字段


@dataclass  
class PageExtractFailureRequest:
    """页面提取失败请求"""
    site_name: str
    error: Exception
    page_number: int
    target_url: Optional[str] = None
    task_id: Optional[str] = None
    worker_id: Optional[str] = None
    max_retry: int = 3


@dataclass
class DetailExtractFailureRequest:
    """详情提取失败请求"""
    site_name: str
    error: Exception
    item_reference: str
    target_url: Optional[str] = None
    failure_data: Optional[Dict[str, Any]] = None
    task_id: Optional[str] = None
    worker_id: Optional[str] = None
    max_retry: int = 3


@dataclass
class DataSaveFailureRequest:
    """数据保存失败请求"""
    site_name: str
    error: Exception
    item_reference: str
    failure_data: Optional[Dict[str, Any]] = None
    task_id: Optional[str] = None
    worker_id: Optional[str] = None
    max_retry: int = 3


@dataclass
class FileDownloadFailureRequest:
    """文件下载失败请求"""
    site_name: str
    error: Exception
    item_reference: str
    target_url: Optional[str] = None
    task_id: Optional[str] = None
    worker_id: Optional[str] = None
    max_retry: int = 3


@dataclass
class RetryRequest:
    """重试请求"""
    record_id: int
    error_message: Optional[str] = None


@dataclass
class FailureQueryRequest:
    """失败记录查询请求"""
    site_name: str
    start_time: Optional[datetime] = None
    end_time: Optional[datetime] = None
    task_id: Optional[str] = None


@dataclass
class CleanupRequest:
    """清理记录请求"""
    site_name: str
    days_to_keep: int = 30
